package com.guigu.liuzhireng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuzhireng.mapper.AccountMapper;
import com.guigu.liuzhireng.pojo.Account;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.liuzhireng.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountMapper accountMapper;

    @Override
    public Account login(Account account) {
        return accountMapper.login(account);
    }

    @Override
    public Account loadAccount(String account) {
        return accountMapper.selectByPrimaryKey(account);
    }

    @Override
    public int update(Account account) {
        return accountMapper.updateByPrimaryKeySelective(account);
    }

    @Override
    public int insert(Account account) {
        return accountMapper.insertSelective(account);
    }

    @Override
    public int delete(String account) {
        return accountMapper.deleteByPrimaryKey(account);
    }


    @Override
    public PageVo<Account> Page(Account account, int num, int size) {
        PageHelper.startPage(num,size);
        List<Account> list = accountMapper.list(account);
        PageInfo<Account> pageInfo = new PageInfo<>(list);
        PageVo<Account> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }
}
